<div class="modal-body pageContent">
    <div class="row">
        <div class="col-lg-12 col-lg-offset-2">
        <form id="ChildOrderEditForm" method="post" class="form-horizontal" action="/order/updateChildOrderList">              
                    <input type="text" class="form-control" style="display:none"  name="orderId" value="{{orderId}}"/>
                    <input type="text" class="form-control" style="display:none"  name="id" value="{{id}}"/>
                <div class="form-group">
                    <label class="col-lg-12 control-label"><span class="indicator">*</span><span class="indicatorName">子订单号</span></label>
                    <div class="col-lg-12">
                        <input type="text" class="form-control" name="childOrderId" value="{{childOrderId}}"/>
                    </div>
                </div>
                <div class="form-row prl10">
                    <div class="form-group col-md-12 ">
                        <label class=" control-label " ><span class="indicator">*</span><span class="indicatorName">SN集合检验</span></label>
                        <div class="row">
                                <div class="col-sm-6  pr20 pl15" >
                                    <input type="text" class="form-control "  name="beginSN" value="{{beginSn}}"  placeholder="开始SN" id="beginSN" />
    
                                </div>
                                <div class="col-sm-6 pr20 pl15" >
                                    <input type="text" class="form-control" placeholder="结束SN" name="endSN" id="endSN" value="{{endSn}}"/>
    
                                </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-12 control-label"><span class="indicator">*</span><span class="indicatorName">数量</span></label>
                    <div class="col-lg-12">
                        <input type="text" class="form-control" name="deviceNum" id="deviceNum"  readonly = "readonly" value="{{num}}" />
                    </div>
                </div>
                 <div class="form-group">
                    <label class="col-lg-12 control-label"><span class="indicator">*</span><span class="indicatorName">控制器</span></label>
                    <div class="col-lg-12">
                         <select id="orderControllerSelect" name="controllerId" class="selectpicker show-tick form-control" title="请选择控制器" >
                                   <option value="{{controllerSn}}"  selected  style="display:none">请选择控制器</option>
                        </select>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="modal-footer pageFooter">
   <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
    <button  class="btn btn-primary"  type="submit" id="displayBtn" >保存</button>
   
</div>
<script type="text/javascript">
$(document).ready(function() {  

    $.ajax({
        url:'/order/getControllerList',
        type:'post',
        data:{'orderId':'{{orderId}}'},
        dataType:'json',
         success:function(json){
                $.each(json,function(i,item){
                        if(item.units!=""){
                                if("{{'controllerEntity[controllerSn]'}}"&& "{{'controllerEntity[controllerSn]'}}"==item.controllerSn){
                                    $('#orderControllerSelect').append('<option value="'+item.id+'" selected>'+item.controllerSn+'('+item.units+')'+'</optinon>')
                                }else{
                                    $('#orderControllerSelect').append('<option value="'+item.id+'">'+item.controllerSn+'('+item.units+')'+'</optinon>')
                                }
                        }else{
                                if("{{'controllerEntity[controllerSn]'}}" &&"{{'controllerEntity[controllerSn]'}}"==item.controllerSn){
                                        $('#orderControllerSelect').append('<option value="'+item.id+'" selected>'+item.controllerSn+'</optinon>')
                                }else{
                                        $('#orderControllerSelect').append('<option value="'+item.id+'">'+item.controllerSn+'</optinon>')
                                }
                        }
                })
                        //  for(var i=0;i<json.length;i++){
                        //     if("{{'controllerEntity[controllerSn]'}}" && "{{'controllerEntity[controllerSn]'}}"==json[i].controllerSn){
                        //          $('#orderControllerSelect').append('<option value="'+json[i].id+'" selected>'+json[i].controllerSn+'</optinon>')
                        //      }else{
                        //         $('#orderControllerSelect').append('<option value="'+json[i].id+'">'+json[i].controllerSn+'</optinon>')
                        //      }
                        //  }
            $('#orderControllerSelect').selectpicker('render');
            $('#orderControllerSelect').selectpicker('refresh');
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
            toastr.error(textStatus+'!');
        }
    })

  var beginsn = "";
  var endSN = "";
   var sum ="";
   $("#beginSN").bind("input propertychange",function(event){
        beginsn = $("#beginSN").val()
          endSN = $("#endSN").val()
       if (endSN!="") { //有值并且需要大于开始sn
         sum = (endSN-beginsn)+1;
          if (sum>0) {
             $("#deviceNum").val(sum).css("color","#000000");
          }else{
             $("#deviceNum").val("结束SN值需大于开始SN").css("color","#f00");
          }
       }
    });
    $("#endSN").bind("input propertychange",function(event){
        beginsn = $("#beginSN").val()
          endSN = $("#endSN").val()
       if (beginsn!="") {
         sum = (endSN-beginsn)+1;
            if (sum>0) {
               $("#deviceNum").val(sum).css("color","#000000");
            }else{
               $("#deviceNum").val("结束SN值需大于开始SN").css("color","#f00");
            }
       }
    });

    $('.selectpicker').selectpicker();//初始化
    $('#ChildOrderEditForm')
        .bootstrapValidator({
            message: '此值无效',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
             fields: {
                childOrderId: {
                    validators: {
                        notEmpty: {
                            message: '请填写子订单号'
                        },
                    }
                },
                beginSN: {
                    validators: {
                        notEmpty: {
                            message: '请填写开始SN'
                        },
                        stringLength: {
                            min: 10,
                            max: 12,
                            message: '字符长度应为10-12位'
                        },
                    }
                },
                  endSN: {
                    validators: {
                        notEmpty: {
                            message: '请填写结束SN'
                        },
                        stringLength: {
                            min: 10,
                            max: 12,
                            message: '字符长度应为10-12位'
                        },
                    }
                },
                //   deviceNum: {
                //     validators: {
                //         notEmpty: {
                //             message: '请填写数量'
                //         },
                //     }
                // },
                
            }
        })
        .on('success.form.bv', function(e) {
            e.preventDefault();
            var $form = $(e.target);
            var bv = $form.data('bootstrapValidator');
            // Use Ajax to submit form data
             $.ajax({
                type: 'post',
                url:$form.attr('action'),
                data:$form.serialize(),
                success: function(result){
                    if(result.length===9371){   //session超时返回的登录页面 避免接口返回的也是字符串不是json
                        location.href="/severError";
                    }else{ 
                        if(result.statusCode =='200'){
                            toastr.success(result.message+'!');
                            $('#editChildOrderPage').modal('hide');
                            //  $("#orderDetailTable").bootstrapTable('refresh');
                            $("#orderDetailTable").bootstrapTable('refresh',{url:"/order/getChildOrderList",silent:true,query:{
                                type:1,
                                level:2
                            }});
                        }else{
                            toastr.warning(result.message+'!');
                        }  
                    }
                },
                error: function (result) {       //后台数据异常返回503
                    if(result.status===503||result.status===500){ 
                        $('#orderListAdd').modal('hide');
                        toastr.error("服务端数据异常"+'!');
                    }
                } 
            })
            // $.post($form.attr('action'), $form.serialize(), function(result) {
            //     if(result.length===9371){   //session超时返回的登录页面 避免接口返回的也是字符串不是json
            //             location.href="/severError";
            //     }else{ 
            //         if(result.statusCode =='200'){
            //             toastr.success(result.message+'!');
            //             $('#editChildOrderPage').modal('hide');
            //             //  $("#orderDetailTable").bootstrapTable('refresh');
            //             $("#orderDetailTable").bootstrapTable('refresh',{url:"/order/getChildOrderList",silent:true,query:{
            //                 type:1,
            //                 level:2
            //             }});
            //         }else{
            //             toastr.warning(result.message+'!');
            //         }  
            //     }             
            // }) 
            // .error(function(result){
            //     if(result.status===503||result.status===500){ 
            //         $('#orderListAdd').modal('hide');
            //         toastr.error("服务端数据异常"+'!');
            //     }
            // });;
        });
});

</script>
